package cn.edu.scau.cmi.wuyihan.exercise11.Example11_8;

import java.util.Arrays;

import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public class PoliceListen implements DocumentListener {

	JTextArea inputText,showText;
	public void setInputText(JTextArea text) {
		inputText = text;
	}
	public void setShowText(JTextArea text) {
		showText = text;
	}
	@Override
	public void changedUpdate(DocumentEvent arg0) {
		// TODO Auto-generated method stub
		String string=inputText.getText();
		String regex="[\\s\\d\\p{Punct}]+";
		String words[]=string.split(regex);
		Arrays.sort(words);
		showText.setText(null);
		for(String s:words) {
			showText.append(s+",");
		}
	}

	@Override
	public void insertUpdate(DocumentEvent arg0) {
		// TODO Auto-generated method stub
		changedUpdate(arg0);
	}

	@Override
	public void removeUpdate(DocumentEvent arg0) {
		// TODO Auto-generated method stub
		changedUpdate(arg0);
	}

}
